package com.cuitrip.business.notice.ui;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cuitrip.business.tripservice.ui.IconTextView;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.cuitrip.util.time.InputTime;
import com.cuitrip.util.time.OutputTime;
import com.cuitrip.util.time.TimeUtil;
import com.lab.component.list.swipe.SwipeLayout;
import com.lab.component.list.viewholder.CTRecycleViewHolder;

import butterknife.Bind;

/**
 * Created by baziii on 15/8/10.
 */
public class MessageViewHolderCT extends CTRecycleViewHolder<MessageMode> {
    public static int RES = R.layout.message_item;
    @Bind(R.id.ct_message_name)
    TextView mMessageName;
    @Bind(R.id.ct_message_time)
    TextView mMessageTime;
    @Bind(R.id.ct_delete)
    View mDelete;
    @Bind(R.id.ct_swip_layout)
    SwipeLayout mSwipLayout;
    @Bind(R.id.ct_message_layout)
    RelativeLayout mMessageLayout;
    @Bind(R.id.message_status)
    IconTextView messageStatusView;

    @Bind(R.id.message_content)
    TextView contentView;

    MessageMode messageMode;

    public MessageViewHolderCT(View itemView, View.OnClickListener mOnClickListener) {
        super(itemView);
        mSwipLayout.setDragEdge(SwipeLayout.DragEdge.Right);
        mSwipLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
        mMessageLayout.setOnClickListener(mOnClickListener);
        mDelete.setOnClickListener(mOnClickListener);
    }

    @Override
    public void render(MessageMode messageMode, int position) {
        this.messageMode = messageMode;
//        mMessageLayout.setTag(messageMode);
        mMessageLayout.setTag(getAdapterPosition());
        mDelete.setTag(messageMode);
        mMessageTime.setText(
                TimeUtil.formatTime(
                        InputTime.build(messageMode.getGmtCreated()),
                        OutputTime.getLocalInstance(OutputTime.OutputType.Type_Minute)
                )
        );
        contentView.setText(messageMode.getContent());
        if (messageMode.isRead) {
            messageStatusView.setTextColor(ResourceUtil.getColor(R.color.ganshi_ded8d7));
            contentView.setTextColor(ResourceUtil.getColor(R.color.ganshi_ded8d7));
        } else {
            messageStatusView.setTextColor(ResourceUtil.getThemeColor());
            contentView.setTextColor(ResourceUtil.getColor(R.color.qiaomai_7c706e));
        }

        if (messageMode.type == MessageMode.SYSTEM_TYPE) {
            messageStatusView.setText(ResourceUtil.getString(R.string.setting_full_icon));
            mMessageName.setText(ResourceUtil.getString(R.string.message_type_system));
        } else {
            messageStatusView.setText(ResourceUtil.getString(R.string.order_icon));
            mMessageName.setText(ResourceUtil.getString(R.string.message_type_book));
        }


    }
}
